package cn.itlaobing.springmvc.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.itlaobing.springmvc.entity.Account;
import cn.itlaobing.springmvc.web.controller.SessionController;
/**
 * 认证
 * @author Administrator
 *
 */
public class AuthorizationInterceptor extends HandlerInterceptorAdapter{
	/**
	 * 鉴别用户是否登陆，如果登陆，则放行，也就是说返回true，调用流程就会进入
	 * Controller中的处理方法
	 * @param request
	 * @param response
	 * @param handler
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler)
					throws Exception{
	HttpSession session = request.getSession();
	//取得当前用户登陆
	Account account = (Account)session.getAttribute(SessionController.CURRENT_ACCOUNT);
	if(account==null){
		//如果没有登陆，则跳转到登陆
		response.sendRedirect("signIn");
		return false;
	}
	return true;
	}
}
